/**
 * @param {string} digits
 * @return {string[]}
 */
var letterCombinations = function (digits) {
  const numMap = {
    2: ['a', 'b', 'c'],
    3: ['d', 'e', 'f'],
    4: ['g', 'h', 'i'],
    5: ['j', 'k', 'l'],
    6: ['m', 'n', 'o'],
    7: ['p', 'q', 'r', 's'],
    8: ['t', 'u', 'v'],
    9: ['w', 'x', 'y', 'z']
  }
  const Arr = digits.split('')
  let res = numMap[Arr[0]]
  if (!res) {
    return []
  }
  const data = arr => {
    res = res
      .map(item1 => {
        const temarr = []
        arr.forEach(item => {
          temarr.push(item1 + item2)
        })
        return [...temarr]
      })
      .flat()
  }
  Arr.forEach((element, index) => {
    index > 0 && data(numMap[element])
  })
  return res
}
console.log(letterCombinations('2'))
